package com.example.easytts.config

import com.example.easytts.model.User
import com.example.easytts.repository.UserRepository
import org.springframework.boot.CommandLineRunner
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder

@Configuration
class AdminUserInitializer {
    @Bean
    fun initAdminUser(userRepository: UserRepository) = CommandLineRunner {
        val username = "admin"
        val password = "admin123"
        val encoder = BCryptPasswordEncoder()
        if (userRepository.findByUsername(username) == null) {
            val admin = User(
                username = username,
                password = encoder.encode(password),
                role = "admin"
            )
            userRepository.save(admin)
            println("[AdminUserInitializer] 管理员账号已创建，用户名：admin，密码：admin123")
        }
    }
} 